package 算法.leetcode.array;

/**
 * @author lchenglong
 * @date 2022/5/11
 */
public class MaxArea {

    public static void main(String[] args) {
        MaxArea maxArea = new MaxArea();
        int ans = maxArea.maxArea(new int[]{1,8,6,2,5,4,8,3,7});
        System.out.println(ans);
    }
    public int maxArea(int[] height) {
        int max = 0;
        for(int i=0,j = height.length-1;i<j;){
            if(height[i]>=height[j]){
                int h = height[j];
                max = Math.max(h *(j-i),max);
                j--;
            } else{
                int h = height[i];
                max = Math.max(h *(j-i),max);
                i++;
            }
        }
        return max;
    }
}
